package com.caac.core.dao.hibernate;

import java.util.Collection;
import java.util.List;

import com.caac.core.dao.ViewPropDao;
import com.caac.core.dm.ViewProp;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright caac 2004</p>
 * <p>Company: caac</p>
 * @author <a href="mailto:project@caac.com.cn">Project Group</a>
 * @version 1.0
 */

public class ViewPropDaoHibernate extends BaseDaoHibernate implements
        ViewPropDao {
    public List getViewPropsByGroupName(String groupName) {
        return getHibernateTemplate().find(
                "from ViewProp vp where vp.groupName = ? order by vp.priority",
                groupName);
    }

    public void deleteViewPropsByGroupName(String groupName) {
        //Iterator entities =  getHibernateTemplate().iterate(
        //        "from ViewProp vp where vp.groupName = ?", groupName);
        List entities = getHibernateTemplate().find(
                "from ViewProp vp where vp.groupName = ?", groupName);
        getHibernateTemplate().deleteAll((Collection) entities);
        //this.execNoResultSql("delete from order_property where group_name='" +
        //              groupName + "'");
    }

    public void saveViewProp(ViewProp vp) {
        getHibernateTemplate().saveOrUpdate(vp);
    }

    public List getViewPropsByGroupName(String groupName, String username) {
        return getHibernateTemplate().find(
                "from ViewProp vp where vp.groupName = ? and vp.username = ? order by vp.priority",
                new String[] {groupName, username});
    }

    public void deleteViewPropsByGroupName(String groupName, String username) {
        //Iterator entities =  getHibernateTemplate().iterate(
        //        "from ViewProp vp where vp.groupName = ?", groupName);
        List entities = getHibernateTemplate().find(
                "from ViewProp vp where vp.groupName = ? and vp.username = ? ",
                new String[] {groupName, username});
        getHibernateTemplate().deleteAll((Collection) entities);
        //this.execNoResultSql("delete from order_property where group_name='" +
        //              groupName + "'");
    }
}
